package com.autoEcole.service;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

import com.autoEcole.dao.PermisDAO;
import com.autoEcole.exception.ApplicationException;
import com.autoEcole.exception.DAOException;
import com.autoEcole.model.Permis;

public class PermisService {
	
	private PermisDAO permisDAO;
	/**
	 * PermisService
	 */
	private static PermisService permisService;
	
	/**
	 * Constructor
	 */
	private PermisService() {
		super();
	}

	/**
	 * Returns the PermisService instance (Design Pattern : Singleton)
	 * 
	 * @return PermisService
	 */
	public static synchronized PermisService getInstance() {
		if (permisService == null)
			permisService = new PermisService();
		return permisService;
	}

	public PermisDAO getPermisDAO() {
		return permisDAO;
	}

	public void setPermisDAO(PermisDAO permisDAO) {
		this.permisDAO = permisDAO;
	}

	public int create(Permis permis) throws ApplicationException {
		try {
			return permisDAO.create(permis);
		} catch (DAOException ex) {
			throw new ApplicationException(ex);
		}
	}

	/**
	 * 
	 */
	public void update(Permis permis) throws ApplicationException {
		try {
			permisDAO.update(permis);
		} catch (DAOException ex) {
			throw new ApplicationException(ex);
		}
	}

	/**
	 * retourne l'element si il existe ou null
	 */
	public Permis findById(int id) throws ApplicationException {
		try {
			return permisDAO.findById(id);
		} catch (DAOException ex) {
			throw new ApplicationException(ex);
		}
	}

	/**
	 * @throws ParseException 
	 * 
	 */
	public List<Permis> findAll() throws ApplicationException, ParseException {
		try {
			return permisDAO.findAll();
		} catch (DAOException ex) {
			throw new ApplicationException(ex);
		}		
	}
	
	/**
	 * 
	 */
	public Map<Integer , Permis> findAllMap() throws ApplicationException {
		try {
			return permisDAO.findAllMap();
		} catch (DAOException ex) {
			throw new ApplicationException(ex);
		}
	}
	
	/**
	 * 
	 */	
	public void delete(int permisId) throws ApplicationException {
		try {
			permisDAO.delete(permisId);
		} catch (DAOException ex) {
			throw new ApplicationException(ex);
		}		
	}
}
